<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/views/common/common.jsp"%>
<link
	href="${imgPath}/plugins/bootstrap-3.3.5-dist/css/bootstrap-theme.min.css"
	rel="stylesheet">
<link href="${imgPath}/css/navbar/bootstrap-submenu.min.css" rel="stylesheet">
<nav class="navbar navbar-default">
	<div class="navbar-header">
		<button class="navbar-toggle" type="button" data-toggle="collapse"
			data-target=".navbar-collapse">
			<span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span>
			<span class="icon-bar"></span> <span class="icon-bar"></span>
		</button>
		<a class="navbar-brand">校园四年运维平台</a>
	</div>
	<div class="collapse navbar-collapse" ng-controller="navbar">
		<ul class="nav navbar-nav">
			<!-- 一级菜单 -->
			<li ng-repeat="access in accesslist" ng-class="{dropdown:access.children!=undefined && access.children.length>0}">
				<!-- 无子菜单 -->
 				<a tabindex="0" ng-show="access.children==undefined || access.children.length==0" href="" ng-click="jump(access);">{{access.name}}</a>
				<!-- 有子菜单 -->
				<a tabindex="0" data-toggle="dropdown" ng-show="access.children!=undefined && access.children.length>0"
					data-submenu> {{access.name}}<span class="caret"></span>
				</a>
				<!-- 有子菜单 -->
				<ul class="dropdown-menu" ng-show="access.children!=undefined && access.children.length>0">
					<!-- 二级菜单 -->
					<li ng-repeat="submenu in access.children"  ng-class="{'dropdown-submenu':submenu.children!=undefined && submenu.children.length>0}">
						<!-- 无三级菜单 -->
						<a tabindex="0" href="" ng-click="jump(submenu);" ng-show="submenu.children==undefined || submenu.children.length==0" >{{submenu.name}}</a>
						<!-- 有三级菜单 -->
						<a tabindex="0" ng-show="submenu.children!=undefined && submenu.children.length>0">{{submenu.name}}</a>
  						<ul class="dropdown-menu" ng-show="submenu.children!=undefined && submenu.children.length>0">
						<!--三级菜单-->
							<li ng-repeat="thirdmenu in submenu.children">
								<a tabindex="0" href="" ng-click="jump(thirdmenu);">{{thirdmenu.name}}</a>
							</li>
						</ul> 
					</li>
				</ul>
			</li>
		</ul>
    	<ul class="nav navbar-nav navbar-right">
			<li><a tabindex="0"
				href="${ctx }/login/out.htm">注销</a></li>
		</ul>
	</div>
</nav>
<script src="${imgPath}/script/bootstrap-submenu.min.js"></script>
<script type="text/javascript">
	
	var myapp = angular.module('myapp', [ 'ui.bootstrap' ]);
	
	myapp.config(['$httpProvider', function ($httpProvider) {    
		  $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
		  $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
		  $httpProvider.defaults.transformRequest = [function(data) {
		        /**
		         * The workhorse; converts an object to x-www-form-urlencoded serialization.
		         * @param {Object} obj
		         * @return {String}
		         */
		        var param = function(obj) {
		            var query = '';
		            var name, value, fullSubName, subName, subValue, innerObj, i;
		 
		            for (name in obj) {
		                value = obj[name];
		 
		                if (value instanceof Array) {
		                    for (i = 0; i < value.length; ++i) {
		                        subValue = value[i];
		                        fullSubName = name + '[' + i + ']';
		                        innerObj = {};
		                        innerObj[fullSubName] = subValue;
		                        query += param(innerObj) + '&';
		                    }
		                } else if (value instanceof Object) {
		                    for (subName in value) {
		                        subValue = value[subName];
		                        fullSubName = name + '[' + subName + ']';
		                        innerObj = {};
		                        innerObj[fullSubName] = subValue;
		                        query += param(innerObj) + '&';
		                    }
		                } else if (value !== undefined && value !== null) {
		                    query += encodeURIComponent(name) + '='
		                            + encodeURIComponent(value) + '&';
		                }
		            }
		 
		            return query.length ? query.substr(0, query.length - 1) : query;
		        };
		 
		        return angular.isObject(data) && String(data) !== '[object File]'
		                ? param(data)
		                : data;
		    }];
		}]);
	myapp.controller('navbar', [ '$scope', '$http', function($scope, $http) {
		
		$scope.jump = function(access) {
			if (!access.url) {
				return;
			}
			window.location.href = '${ctx }' + access.url;
		};
		$http.get('${ctx}home/menus.htm').success(function(data) {
			$scope.accesslist = data.data;
			setTimeout(function() {
				$('[data-submenu]').submenupicker();
			}, 500);
		});

	} ]);
</script>